const fs = require("fs");
const path = require("path");
const WriteStream = require("./WriteStream");
const ReadStream = require("./ReadStream");

const rs = new ReadStream(path.resolve(__dirname, "copy.txt"), {
  flags: "r", // 默认不写就是 r 表示我要读取
  autoClose: true,
  emitClose: true,
  start: 0,
  highWaterMark: 4, // 写入 不代表一次写几个，而是表示我的预期
  encoding: "utf8",
});

const ws = new WriteStream(path.resolve(__dirname, "copy1.txt"), {
  flags: "w", // 默认不写就是 r 表示我要读取
  autoClose: true,
  emitClose: true,
  start: 0,
  highWaterMark: 1, // 写入 不代表一次写几个，而是表示我的预期
  encoding: "utf8",
});

rs.pipe(ws);
// 此方法是异步的可以是实现文件的拷贝，缺点就是无法看到中间过程
